package com.situ.mall.service.impl;

import com.situ.mall.entity.User;
import com.situ.mall.mapper.UserMapper;
import com.situ.mall.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements IUserService {
    private Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Autowired
    private UserMapper userMapper;

    // @Transactional(propagation = Propagation.SUPPORTS)
    @Transactional
    @Override
    public List<User> selectAll() {
        // 记录开始时间
        //long begin = System.currentTimeMillis();
        List<User> list =  userMapper.selectAll();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 记录结束执行时间
       /* long end =  System.currentTimeMillis();
        long takeTime = end - begin;
        if (takeTime > 3000) {
            logger.error("====执行结束，耗时：{}毫秒=====", takeTime);
        } else if (takeTime > 2000){
            logger.warn("====执行结束，耗时：{}毫秒=====", takeTime);
        } else {
            logger.info("====执行结束，耗时：{}毫秒=====", takeTime);
        }*/

        return  list;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteById(Integer id) {

    }
}
